package com.gymmsystem.GYMMSystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gymmsystem.GYMMSystem.entity.Coaches;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CoachesMapper extends BaseMapper<Coaches> {

    /**
     * 查询所有在职教练（按入职时间倒序）
     */
    @Select("SELECT * FROM coaches ORDER BY created_at DESC")
    List<Coaches> findAllCoaches();

    /**
     * 根据专长查询教练
     */
    @Select("SELECT * FROM coaches WHERE specialty LIKE CONCAT('%', #{specialty}, '%')")
    List<Coaches> findCoachesBySpecialty(@Param("specialty") String specialty);

    /**
     * 根据从业年限范围查询教练
     */
    @Select("SELECT * FROM coaches WHERE experience BETWEEN #{minExperience} AND #{maxExperience} ORDER BY experience DESC")
    List<Coaches> findCoachesByExperienceRange(@Param("minExperience") Integer minExperience,
                                               @Param("maxExperience") Integer maxExperience);

    /**
     * 根据手机号查询教练
     */
    @Select("SELECT * FROM coaches WHERE phone = #{phone}")
    Coaches findCoachByPhone(@Param("phone") String phone);

    /**
     * 更新教练信息
     */
    @Update("UPDATE coaches SET name = #{name}, phone = #{phone}, specialty = #{specialty}, " +
            "experience = #{experience}, image_url = #{imageUrl} WHERE id = #{id}")
    int updateCoachById(Coaches coach);

    /**
     * 查询经验丰富的教练（3年以上）
     */
    @Select("SELECT * FROM coaches WHERE experience >= 3 ORDER BY experience DESC")
    List<Coaches> findExperiencedCoaches();

    /**
     * 根据姓名模糊查询教练
     */
    @Select("SELECT * FROM coaches WHERE name LIKE CONCAT('%', #{name}, '%')")
    List<Coaches> findCoachesByName(@Param("name") String name);
}